<?php
/* @var $model Invoice */
if ($action == 'update'):
    ?>

<li><a class="return-button" href="javascript:void(0)" onclick="save({link:'<?php echo Yii::app()->request->getUrlReferrer()?>'});">Save & Return</a></li>



<li><a  class="save-button"  href="javascript:void(0)" onclick="save(null);">Save</a></li>


<li><a class="delete-button" href="index.php?r=invoices/cancel&delete=1&invoice=<?= $model->invoice ?>"
       onclick="return confirm('Are you sure to delete this item?')">Delete</a></li>
<br/>
<?php if(InvoiceUnlocker::isInvoiceUnlocked($model->invoice)===false):?>
<li><a href="javascript:void(0)" onclick="createSalesOrders();">Convert to Sales Order</a></li>
<?php endif;?>
<br/><h5 style="padding-left:11px;"> Delivery</h5>
   <?php if($model->location->disableemails): ?>
    <li><a  class="email-button"  href="#" id="mailForm" onclick="">E-Mail</a></li>
    <?php else: ?>
       <li><a  class="email-button"  href="#" id="mailEmpForm" onclick="">E-Mail</a></li>
    <?php endif; ?>
<li><a class="print-button" href="javascript:void(0)" onclick="save({link:'index.php?r=pdf&invno=<?= $model->invoice ?>',newtab:true,print:true});">View/Print</a></li>
<?php elseif ($action == 'view'): ?>
<li>
    <?php 
    if(InvoiceUnlocker::canRenderUnlockButton()){
        echo CHtml::link('Unlock', array('invoices/unlockInvoice','invoice'=>$model->invoice),array('class'=>'lock-button'));
    }
    ?>
</li>

<?php if ($model->getSalesOrders()!=NULL): ?>
    <li><a  class="view-button" href="index.php?r=invoices/update&invoice=<?= $model->getSalesOrders()->invoice ?>">View Sales Order</a></li>

    <?php endif ?>
<li><a class="delete-button" href="index.php?r=invoices/cancel&delete=1&invoice=<?= $model->invoice ?>"
       onclick="return confirm('Are you sure to delete this item?')">Delete</a></li>
       <?php if($model->jobnumber!=null){
                   echo '<li>';
                   echo CHtml::link('Go to Job',array('/jobs/update','jobid'=>$model->jobnumber),array('class'=>'return-button')); 
                   echo '</li>';
                }?>
       <br/><h5 style="padding-left:11px;"> Delivery</h5>
<li><a class="print-button" target="_blank" onclick="printSelect({link:'index.php?r=pdf&invno=<?= $model->invoice ?>',newtab:true})" >View/Print</a>
   <?php if($model->location->disableemails): ?>
    <li><a  class="email-button"  href="#" id="mailForm" onclick="">E-Mail</a></li>
    <?php else: ?>
       <li><a  class="email-button"  href="#" id="mailEmpForm" onclick="">E-Mail</a></li>
    <?php endif; ?>
<?php endif?>

